from app.extension.database.sqlalchemy import sqla_db as db
from datetime import datetime
from .base_model import BaseModel


class CategoryModel(db.Model, BaseModel):
    """商品分类模型"""
    __tablename__ = 'tb_category'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), comment='类别名称')
    img_id = db.Column(db.String(255), comment='类别对应的图片')
    create_time = db.Column(db.DateTime, default=datetime.now)
    delete_time = db.Column(db.DateTime)

    def __init__(self, data: dict):
        self.name = data.get('name')
        self.img_id = data.get('img_id')

    @staticmethod
    def check_category(ids):
        count = CategoryModel.query.filter(CategoryModel.id.in_(ids)).count()
        print('check_image cuont:', count)
        return count == len(set(ids))